package logic

import (
	"bw-renting/model/mysql"
	"bw-renting/user-rpc/internal/svc"
	"bw-renting/user-rpc/user"
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"strconv"
)

type SetPasswordLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetPasswordLogic {
	return &SetPasswordLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo: 用户设置密码
func (l *SetPasswordLogic) SetPassword(in *user.SetPasswordReq) (*user.SetPasswordRes, error) {
	// todo: add your logic here and delete this line
	id, err := strconv.Atoi(in.UserId)
	if err != nil {
		return &user.SetPasswordRes{
			Status: "0",
		}, nil
	}
	u := mysql.SetPassword(id, in.Password)
	if u.ID == 0 {
		return &user.SetPasswordRes{
			Status: "0",
		}, nil
	}
	return &user.SetPasswordRes{
		Status: "1",
	}, nil
}
